package cn.umakr.util;

import org.apache.commons.dbutils.DbUtils;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class DbHelper {

	public static Connection getConn() {

		Connection conn = null;
		try {
			InputStream is = DbHelper.class.getResourceAsStream("/cn/umakr/dbc.properties");
			Properties prop = new Properties();
			prop.load(is);
			//应用DBUtil加载mysql驱动
			if (!DbUtils.loadDriver(prop.getProperty("jdbc.driver"))) {
				throw new RuntimeException("装载数据库驱动失败");
			}
			String url = prop.getProperty("jdbc.url");
			String username = prop.getProperty("jdbc.username");
			String password = prop.getProperty("jdbc.password");
			conn = DriverManager.getConnection(url, username, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return conn;
	}
	
	public static void main(String[] args) {
		
		DbHelper.getConn();
	}
}
